﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PivotCollectionTools.Xml;

namespace PivotCollectionTools.Xml.Test
{
    /// <summary>
    /// Summary description for WorkflowTestig
    /// </summary>
    [TestClass]
    public class WorkflowTesting
    {
        public WorkflowTesting()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void UpdateCXML1()
        {
            PivotXml collection = PivotXml.CreateFromXml(@"D:\data\GymManager\MyCollection\CarCollection.cxml");
            collection.ItemList[0].Items[0].Name = "This is a test";
            collection.ItemList[0].Items[0].Tags.Add(new Tag() { Value = "testTag" });
            collection.WriteXml(@"D:\data\GymManager\MyCollection\CarCollectionUpdate1.cxml");
        }

        [TestMethod]
        public void UpdateCXML2()
        {
            PivotXml collection = PivotXml.CreateFromXml(@"D:\data\GymManager\MyCollection\CarCollection.cxml");
            collection.ItemList[0].Items[0].Facets["Fuel"].Text[0].Value = "Water";
            collection.ItemList[0].Items[0].Facets.AddTextFacet("Fuel", "Gas");
            collection.WriteXml(@"D:\data\GymManager\MyCollection\CarCollectionUpdate2.cxml");
        }



        [TestMethod]
        public void CreatingPivotXml()
        {
            var collection = new PivotXml();

            // Names the colleciton the name attribute of the collection element.
            collection.Name = "Car Collection";

            // Create a new Facet Category
            var category = new FacetCategory(
                "Category One",                 // Name of the Category.
                FacetDataType.String,           // Facet Data type.
                true,                           // Filter visablity is true
                true,                           // Show in info panel true
                true);                          // Include in the keyword search

            // Add new Facet Category to collection.
            collection.AddCategory(category);

            // Create a new item list and specifing the relative path to the 
            // Deep Zoom DZC
            var imageList = new ItemList() { ImageBase = "dzm\\dzm.dzc" };

            // containing this collection’s images.
            collection.ItemList.Add(imageList);

            // Create a new Item.
            var collectionItem = new Item("0")
            {
                Name = "Item",
                Image = "#0"
            };

            // Add a facet string value for the Category One.
            collectionItem.Facets.AddTextFacet("Category One", "Value");

            // Add the item to the item list.
            collection.ItemList[0].Items.Add(collectionItem);

            // Now write to a CXML file.
            collection.WriteXml("car.cxml");
        }
    }
}
